import os

def file_name(file_dir,output_train_path,output_valid_path):
    L=[]
    f_train = open(output_train_path, 'a')
    f_valid = open(output_valid_path, 'a')
    idx = 0
    for root, dirs, files in os.walk(file_dir):
        for file in files:
            if os.path.splitext(file)[1] == '.xml':
                # L.append(os.path.join(root, file))
                file=file.split(".xml")
                # L.append(file[0])
                # f.write('\n' + str(i))
                if idx % 10 == 0:
                    f_valid.write('data/custom/images/'+ file[0]+'.png' + '\n')
                else:
                    f_train.write('data/custom/images/'+ file[0]+'.png' + '\n')
            idx = idx + 1
    f_train.close()
    f_valid.close()
    # return L

if __name__=='__main__':
    table=file_name('./Annotations/','./train.txt','./valid.txt')
    print(table)